define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'expressfee/index' + location.search,
                    add_url: 'expressfee/add',
                    edit_url: 'expressfee/edit',
                    del_url: 'expressfee/del',
                    multi_url: 'expressfee/multi',
                    table: 'expressfee',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        // {field: 'supplier_id', title: __('Supplier_id')},
                        {field: 'id', title: __('查看地区'), formatter: Controller.api.formatter.id,operate:false},
                        {field: 'id', title: __('具体设置'), formatter: Controller.api.formatter2.id,operate:false},
                        {field: 'name', title: __('Name')},
                        {field: 'wuliu', title: __('物流名称')},
                        {field: 'type', title: __('Type'), searchList: {"0":__('Type 0'),"1":__('Type 1'),"2":__('Type 2')}, formatter: Table.api.formatter.normal},
                       /* {field: 'qb_price', title: __('Qb_price'), operate:false},*/
                      /* {field: 'unit', title: __('Unit'), operate:false},*/
                     /*   {field: 'inc_price', title: __('计算方式'), operate:false},
                        {field: 'unit', title: __('计算单位'), operate:false},*/
                      //  {field: 'freeship', title: __('计算单位')},
                        // {field: 'is_del', title: __('Is_del')},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ],
                search:false,
                showColumns: false,
                showToggle: false,
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            },
            formatter: {
                id: function (value, row, index) {
                    //这里手动构造URL
                    var ids = row['id'];
                    var supplier_id = row['supplier_id'];

                    // var store_id = row['store_id'];
                    
                    url = "Expressfee/city_list?id=" + ids + "&supplier_id=" + supplier_id;
                    //方式一,直接返回class带有addtabsit的链接,这可以方便自定义显示内容

                    if(row.type=="0")
                    {
                        return '<a href="' + url + '" class="label label-success addtabsit" title="' + __("非免邮地区", value) + '">' + '非免邮地区' + '</a>';
                    }
                    else
                    {
                        return '<a href="' + url + '" class="label label-success addtabsit" title="' + __("设置地区", value) + '">' + '设置地区' + '</a>';
                    }


                }
           } ,
            formatter2: {
                id: function (value, row, index) {
                    //这里手动构造URL
                    var ids = row['id'];
                    var supplier_id = row['supplier_id'];

                    // var store_id = row['store_id'];

                    url = "Expressfee/info?id=" + ids + "&supplier_id=" + supplier_id;
                    //方式一,直接返回class带有addtabsit的链接,这可以方便自定义显示内容

                    if(row.type=="0")
                    {
                        return '<a href="' + url + '" class="label label-success addtabsit" title="' + __("非免邮地区运费设置", value) + '">' + '非免邮地区运费设置' + '</a>';
                    }
                    else
                    {
                        return '<a href="' + url + '" class="label label-success addtabsit" title="' + __("运费设置", value) + '">' + '运费设置' + '</a>';
                    }



                }
            }

        }
    };
    return Controller;
});